<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>新增商户</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
<link rel="stylesheet" href="../../css/public.css" media="all">
<style>
    body {
        background-color: #ffffff;
    }
</style>
</head>
<body>
<div class="layui-form layuimini-form">
    <form class="layui-form layui-form-pane" action="" lay-filter="myForm">
    <div class="layui-form-item">
        <label class="layui-form-label required">权限名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="" placeholder="请输入权限名称" value=""
                   class="layui-input">
        </div>
    </div>
        <input type="hidden" id="pid" name="pid">
        <input type="hidden" id="ppid" name="ppid">
    <div class="layui-form-item">
        <label class="layui-form-label required">所属菜单</label>
        <div class="layui-input-block">
            <input type="text" id="inputid" name="" lay-verify="required" lay-reqtext="" placeholder="请选择所属菜单"
                   value="" class="layui-input" readonly >
        </div>
    </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">权限地址</label>
            <div class="layui-input-block">
                <textarea name="url" placeholder="请输入权限地址" class="layui-textarea"></textarea>
            </div>
        </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">描述</label>
        <div class="layui-input-block">
            <input type="text" name="description" placeholder="请输入描述" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
    </form>
</div>
<script src="../../lib/layui/layui.js" charset="utf-8"></script>
<script src="../../js/provider/layutil.js" charset="utf-8"></script>
<script src="https://cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        //监听提交
        var titlle = localStorage.getItem("title");

        var currentPid = $("#pid").val();


        form.on('submit(saveBtn)', function (data) {
            var str = "确定新增权限信息？";

            layer.confirm(str, {btn: ['确定', '取消'], title: "提示"}, function (index) {
                if($("#ppid").val()=='1'||$("#ppid").val()=='0'){
                    layer.msg("父级菜单不能添加权限！");
                    return false;
                }else{
                    $.ajax({
                        url: '/channel/sys-permission/add',
                        type: 'POST',
                        dataType: 'json',
                        data:data.field,
                        headers:{'Authorization':'Bearer '+ JSON.parse(localStorage.getItem('userdetail')).token},
                        success: function(data) {
                            layer.msg("新增权限成功", {
                                icon: 6,//成功的表情
                                time: 1000 //1秒关闭（如果不配置，默认是3秒）
                            }, function () {
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                            });
                        },
                        error:function (data) {
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        }
                    });
                }
            });
            return false;
        });

        $(document).on('click','#inputid',function (obj) {
            var defaultMenu = {id: $("#pid").val()};
            layutil.menuSelector(defaultMenu, function (res) {
                $("#ppid").val(res.pid);
                $("#inputid").val(res.title);
                $("#pid").val(res.id);
            });
        });
    });

</script>
    </body>
</html>